/*
Copyright (c) 2009, Young Digital Planet SA
All rights reserved.

* Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this 
  list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, 
  this list of conditions and the following disclaimer in the documentation 
  and/or other materials provided with the distribution.
* Neither the name of the Young Digital Planet SA nor the names of its 
  contributors may be used to endorse or promote products derived from this 
  software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
package pl.ydp.jobs.events
{
	import flash.events.Event;
	
	import pl.ydp.jobs.IJobInfo;
	import pl.ydp.jobs.YJobs;
	import pl.ydp.jobs.jobs_internal;
	
	use namespace jobs_internal;

	public class JobForkEvent extends Event
	{
		/**
		 * Event fired when job is spinned of in jobs hierarchy.
		 * Event of such type are bubbled upwards jobs tree.
		 * @eventType jobAddPart
		 */
		public static const JOB_ADD_PART:String = YJobs.JOB_ADD_PART;
		
		/**
		 * Event fired when job is added to any job contained given manager 
		 * or manager itsef. Fired once for every added job (despite how many
		 * time job is added to different containers)
		 * @eventType jobAdded
		 */
		public static const JOB_ADDED:String = YJobs.JOB_ADDED;
		/**
		 * Identifier for event fired when job is removed from any job contained 
		 * given manager or manager itself. Jobs are removed when they receive done()
		 * signal.
		 * @eventType jobRemoved
		 */
		public static const JOB_REMOVED:String = YJobs.JOB_REMOVED;
		
		jobs_internal var m_explicitTarget:Object;
		jobs_internal var m_explicitCurrentTarget:Object;
		
		private var m_job:IJobInfo;
		
		/**
		 * Create job fork event... This event bubbles throught job
		 * hierarchy.
		 * @param type event type
		 * @paran nJob addded job
		 * @param fType fork type (addPart/spinOff)
		 * @see #TYPE_SPIN_OFF
		 * @see #TYPE_ADD_PART
		 */
		public function JobForkEvent(type:String, forkedJob:IJobInfo )
		{
			super(type, true, true );
			
			m_job = forkedJob;
		}
		
		public function get forkedJob():IJobInfo {
			return m_job;
		}
		
		override public function clone():Event {
			var fe:JobForkEvent = new JobForkEvent(type, m_job);
			fe.m_explicitTarget = m_explicitTarget;
			fe.m_explicitCurrentTarget = m_explicitCurrentTarget;
			
			return fe;
		}
		
		override public function get target():Object {
			return m_explicitTarget==null ? super.target : m_explicitTarget;
		}
		
		override public function get currentTarget():Object {
			return m_explicitCurrentTarget==null ? super.target : m_explicitCurrentTarget;
		}
	}
}